package cn.itsy.dao.warnrule;

import cn.itsy.pojo.ResultPojo;
import cn.itsy.pojo.Warnrule;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-06-03 15:56
 */
@Repository(value = "warnRuleDaoimpl")
public class WarnRuleDaoimpl implements WarnRuleDao {
    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Warnrule> queryWarnruleAll(String sql) {
        List<Warnrule> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Warnrule>(Warnrule.class));
        return query;
    }

    @Override
    public void insertWarnrule(String sql, Warnrule warnrule) {
        this.jdbcTemplate.update(sql, warnrule.getId(), warnrule.getWrname(), warnrule.getWarntypeId(), warnrule.getWdatenumber(),
                warnrule.getDepts(), warnrule.getComparecolumn(), warnrule.getMaxday(), warnrule.getIsEstatus(),
                warnrule.getIsCstatus(), warnrule.getUserId(), warnrule.getStatus(), warnrule.getEmpId());
    }

    @Override
    public void updateWarnrule(String sql, Warnrule warnrule) {
        this.jdbcTemplate.update(sql, warnrule.getWrname(), warnrule.getWarntypeId(),
                warnrule.getWdatenumber(), warnrule.getDepts(), warnrule.getId());
    }

    @Override
    public void deleteWarnrule(String sql, Warnrule warnrule) {
        this.jdbcTemplate.update(sql, warnrule.getId());
    }

    @Override
    public List<ResultPojo> queryResultPojoById(String sql, Integer id) {
        List<ResultPojo> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<ResultPojo>(ResultPojo.class), id);
        return query;
    }
}
